package com.niiwoo.civet.account.enums;/**
 * Created by DELL on 2017/12/13.
 */

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Objects;

/**
 * 收支类型枚举
 *
 * @author xiaoyingping
 * @create 2017-12-13 21:45
 **/
@AllArgsConstructor
@Getter
public enum InoutTypeEnum {

    IN_TYPE((byte) 1, "收入"),
    OUT_TYPE((byte) -1, "支出");

    private Byte type; //收支类型
    private String desc;  //类型说明

    public static InoutTypeEnum getEnumByCode(byte enumCode) {
        if (Objects.nonNull(enumCode)) {
            for (InoutTypeEnum retEnum : InoutTypeEnum.values()) {
                if (enumCode == retEnum.type) {
                    return retEnum;
                }
            }
        }
        return null;
    }

    public static InoutTypeEnum getReverse(byte enumCode) {
        if(InoutTypeEnum.IN_TYPE.getType() == enumCode){
            return InoutTypeEnum.OUT_TYPE;
        }else if(InoutTypeEnum.OUT_TYPE.getType() == enumCode){
            return InoutTypeEnum.IN_TYPE;
        }else {
            throw new RuntimeException("InoutTypeEnum是不存在:" + enumCode);
        }
    }
}
